WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce Improved External Products
Code in improved_external_prod.php overriding hooks (4 posts)

  1. datafeedr
    Member
    Posted 7 months ago #

    Hi,

    Your plugin is very useful & simple. However there's a problem in your improved_external_prod.php file. Because you are getting the "_product_url" and "_button_text" directly from the postmeta table using get_post_meta(), you are bypassing any filters that might get applied to that data.

    May I suggest changing this:

    function woocommerce_external_add_to_cart() {
    		global $product;
    
    		$product_url = get_post_meta( $product->id, '_product_url', true  );
    		$button_text = get_post_meta( $product->id, '_button_text', true  );
    
    		if ( ! $product_url ) return;
    
    		woocommerce_get_template( '../../woocommerce-improved-external-products/external.php', array(
    				'product_url' => $product_url,
    				'button_text' => ( $button_text ) ? $button_text : __( 'Buy product', 'woocommerce' ) ,
    			) );
    	}

    To this:

    function woocommerce_external_add_to_cart() {
    		global $product;
    
    		if ( ! $product->get_product_url() )
    			return;
    
    		woocommerce_get_template( '../../woocommerce-improved-external-products/external.php', array(
    				'product_url' => $product->get_product_url(),
    				'button_text' => $product->single_add_to_cart_text()
    			) );
    	}

    This will still allow your plugin to call your custom external.php file for adding the target="_blank" code however it won't bypass any WC hooks being applied to the product URL or button text.

    Thanks,
    Eric

    http://wordpress.org/plugins/woocommerce-improved-external-products/

  2. Jeremiah
    Member
    Plugin Author

    Posted 7 months ago #

    Thanks for the suggestion! I'll see if I can push this out in the next week or so. The plugin is definitely due for an update as it's been quite awhile...

  3. datafeedr
    Member
    Posted 7 months ago #

    Thanks for the quick reply! That would be fantastic.

    Eric

  4. viewridge
    Member
    Posted 5 months ago #

    Hello, I was curious if you've made any progress in making the changes to your plugin as discussed above. Thanks for your time.

Reply

You must log in to post.

About this Plugin

About this Topic