id = 'per_product'; $this->desc = __( 'Per Product', 'add-to-cart-button-labels-for-woocommerce' ); parent::__construct(); if ( 'yes' === get_option( 'alg_wc_add_to_cart_button_labels_per_product_enabled', 'no' ) ) { add_action( 'add_meta_boxes', array( $this, 'add_custom_add_to_cart_meta_box' ) ); add_action( 'save_post_product', array( $this, 'save_custom_add_to_cart_meta_box' ), PHP_INT_MAX, 2 ); } } /** * save_custom_add_to_cart_meta_box. * * @version 1.0.0 * @since 1.0.0 */ function save_custom_add_to_cart_meta_box( $post_id, $post ) { // Check that we are saving with custom add to cart metabox displayed. if ( ! isset( $_POST['alg_wc_custom_add_to_cart_save_post'] ) ) { return; } update_post_meta( $post_id, '_' . 'alg_wc_add_to_cart_button_labels_' . 'single', $_POST[ 'alg_wc_add_to_cart_button_labels_' . 'single' ] ); update_post_meta( $post_id, '_' . 'alg_wc_add_to_cart_button_labels_' . 'archive', $_POST[ 'alg_wc_add_to_cart_button_labels_' . 'archive' ] ); } /** * add_custom_add_to_cart_meta_box. * * @version 1.0.0 * @since 1.0.0 */ function add_custom_add_to_cart_meta_box() { add_meta_box( 'alg-wc-custom-add-to-cart', __( 'Custom Add to Cart Button Labels', 'add-to-cart-button-labels-for-woocommerce' ), array( $this, 'create_custom_add_to_cart_meta_box' ), 'product', 'normal', 'high' ); } /** * create_custom_add_to_cart_meta_box. * * @version 1.2.0 * @since 1.0.0 */ function create_custom_add_to_cart_meta_box() { $current_post_id = get_the_ID(); $options = array( 'single' => __( 'Single product view', 'add-to-cart-button-labels-for-woocommerce' ), 'archive' => __( 'Product category (archive) view', 'add-to-cart-button-labels-for-woocommerce' ), ); $html = ''; foreach ( $options as $option_key => $option_desc ) { $option_id = 'alg_wc_add_to_cart_button_labels_' . $option_key; $option_value = get_post_meta( $current_post_id, '_' . $option_id, true ); $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
' . $option_desc . ''; $html .= ''; $html .= '
'; $html .= ''; echo $html; } /** * get_settings. * * @version 1.2.0 * @since 1.0.0 */ function get_settings() { $settings = array( array( 'title' => __( 'Per Product Options', 'add-to-cart-button-labels-for-woocommerce' ), 'type' => 'title', 'desc' => __( 'This section lets you set Add to Cart button text on per product basis. When enabled, label for each product can be changed in "Edit Product".', 'add-to-cart-button-labels-for-woocommerce' ), 'id' => 'alg_wc_add_to_cart_button_labels_per_product_options', ), array( 'title' => __( 'Per Product Labels', 'add-to-cart-button-labels-for-woocommerce' ), 'desc' => '' . __( 'Enable section', 'add-to-cart-button-labels-for-woocommerce' ) . '', 'id' => 'alg_wc_add_to_cart_button_labels_per_product_enabled', 'default' => 'no', 'type' => 'checkbox', ), array( 'type' => 'sectionend', 'id' => 'alg_wc_add_to_cart_button_labels_per_product_options', ), ); return $settings; } } endif; return new Alg_WC_Add_To_Cart_Button_Labels_Settings_Per_Product();